<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>while练习</title>
    <script>
        /* while练习 */
        /* 
        投资年利率为5%,试求从1000块增长到500块，需要花费多少年
        */
        var money = 1000,
            year = 0;
        while (money < 5000) {
            money = money * 1.05;
            year++;
        }
        document.write("需要" + year + "年");
    </script>
</head>

<body>

</body>

</html>